{extend name="layout/detail" /}
{block name="content"}
<div class="td-content-wrap p20">
    <div class="td-content-header">
        <h1 class="main-title">配置分类</h1>
    </div>
    <hr>
    <div class="panel no-border">
        <a class="layui-btn" onclick="go_return_url();">返回</a>
        <span class="mid"></span>
        <a class="layui-btn" onclick="add();">添加配置分类</a>
        <a class="layui-btn" onclick="add_config();">添加配置</a>
    </div>
    <hr>
    <form id="form_data" class="layui-form">
        <table id="data_table" lay-filter="data_table"></table>
    </form>
</div>
{/block}

{block name="script"}
<script type="text/html" id="tool_bar">
    <a class="layui-btn layui-btn-xs" lay-event="system_config">编辑配置</a>
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<script type="text/html" id="sign_qty">
    {{d.start}} ~ {{d.end}}
</script>
<script type="text/html" id="sort">
    <span class="handle" data-id="{{d.id}}" data-sort="{{d.sort}}"><i class="iconfont td-tuodong pointer"></i></span>
</script>
<script>
    layui.use(['common', 'data_table', 'form'], function () {
        let $ = layui.jquery;
        let data_table = layui.data_table;
        let form = layui.form;

        // 记录返回地址
        set_return_url();

        // 页面用到方法
        let fn = {
            system_config: function (data) {
                window.open('{:url("system_config/admin")}?config_tab_id=' + data.id, '_self');
            },
            add_config: function (data) {
                window.open('{:url("system_config/add")}', '_self');
            },
            add: function (data) {
                window.open('{:url("add")}', '_self');
            },
            read: function (data) {
                window.open('{:url("read")}?id=' + data.id, '_self');
            },
            edit: function (data) {
                window.open('{:url("edit")}?id=' + data.id, '_self');
            },
            is_top: function (data) {
                popup_open('{:url("is_top")}?id=' + data.id, 630, 350);
            },
            tag: function (data) {
                popup_open('{:url("tag")}?id=' + data.id, 630, 350);
            },

            import_article: function () {
                window.open('{:url("import_article")}', '_self');
            },
            export_to_excel: function () {
                $form_adv_search = $("#form_adv_search");
                $form_adv_search.attr('action', "{:url('export_to_excel')}");
                $form_adv_search.attr('target', '_blank');
                $form_adv_search.submit();
            },
            del: function (data) {
                layer.msg('确定要删除吗?', {
                    time: 0,
                    btn: ['确定', '取消'],
                    yes: function (index) {
                        var vars = 'id=' + data.id;
                        $.get("{:url('del')}", vars, function (res) {
                            if (res.code) {
                                layer.msg(res.msg, {
                                    time: 1200
                                }, function () {
                                    location.reload(true);
                                });
                            } else {
                                layer.msg(res.msg);
                            }
                        });
                    },
                    no: function (index) {
                        layer.close(index);
                    }
                });
            },
        };

        win_exp(fn);

        let cols = [
            [{
                    toolbar: '#sort',
                    align: 'center',
                    width: 50,
                },
                {
                    field: 'name',
                    title: '分类名称',
                    minWidth: 160
                },
                {
                    field: 'code',
                    title: '分类代码',
                    width: 120,
                },
                {
                    toolbar: '#icon',
                    field: 'icon',
                    title: '图标',
                    width: 120
                },
                {
                    field: 'type',
                    title: '类型',
                    width: 120,
                },
                {
                    toolbar: '#tool_bar',
                    title: '操作',
                    width: 210,
                    fixed: 'right',
                }
            ]
        ];

        data_table.config.cols = cols;
        data_table.render();

    });
</script>
{/block}